<?php if (isset($add)) echo "<h2>Thêm Địa Điểm</h2>"; else echo "<h2>Thay đổi thông tin địa điểm</h2>";?>
<form name="edit_tour" action="?act=createOrModifyLocation&location_id=<?php echo (isset($location_id)? $location_id:"")  ?>" method="POST" onsubmit="return validate_values()" enctype="multipart/form-data">
	<?php
		$location = new location();
		if (!isset($add))
		  $location->select($location_id);
	?>
	<div class='row_field'>
    	<div class='label'>
			<label for="location_code">Mã Địa Điểm(*):</label>
        </div>
        <div class='field'>
			<input class='inputbox' type="text" id="location_code" name="location_code" value="<?php echo $location->getcode() ?>">
        </div>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="location_name">Tên Địa Điểm(*):</label>
        </div>
        <div class='field'>
			<input class='inputbox' type="text" id="location_name" name="location_name" value="<?php echo $location->getname()?>">
        </div>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="country">Quốc Gia(*):</label>
		</div>
		<?php $countries = Country::getAllCountries(); ?>		
		<div class='field'>
            <select id="country" name="country">
                <?php				
    
                    foreach ($countries as $country) {
                    ?>
                    <option value="<?php echo $country->getid()?>" <?php echo ($country->getid()==$location->getcountry())?"selected='selected'":""?>>					
                        <?php echo $country->getname() ?>
                    </option>
                    <?
                    }
                ?>
            </select>
        </div>
	</div>
	
	<div class='row_field'>
		<label for="description">Miêu tả Địa Điểm(*):</label>
		<?php
		include("../fckeditor.php");
		$sBasePath = $_SERVER['PHP_SELF'] ;
		$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ) ;
		
		$oFCKeditor = new FCKeditor('description') ;
		$oFCKeditor->BasePath	= $sBasePath ;
		$oFCKeditor->Value		= $location->getdescription();
		$oFCKeditor->Height		= 300;
		$oFCKeditor->Create() ;
		?>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="active">Hiệu lực:</label>
        </div>
        <div class='field'>
			<input type="checkbox" id="active" name="active" <?php if ($location->getactive() == 1 || isset($add)) echo 'checked="true"'?>>
        </div>
	</div>
		
	<div class='row_field'><p>(*) Thông tin bắt buộc</p></div>
	<div class='row_field'>
		<input type="submit" value="Save">
	</div>
	
</form>
<script type="text/javascript">
	function validate_values() {
		name = $('#location_name').val();
		code = $('#location_code').val();
		description = $('#description').val();
		
		message = "Các mục sau đây là bắt buộc hoặc sai giá trị: \n";
		ok = true;
		if (name == "") {
			message += "Tên Địa Điểm \n";
			ok = false;
		}
		if (code == "") {
			message += "Mã Địa Điểm \n";
			ok = false;
		}
		if (!ok) alert(message);
		return ok;
	}
	
	
	function add_more_picture() {
		picture_list = $('#pictures_list');
		index = picture_list.find("div").size() + 1;
		pic_div = '<div id="div_picture'+index+'"><input type="file" id="picture'+index+'" name="picture_'+index+'"><input type="button" value="Xoa" onclick="remove_picture('+index+', null)"></div>';
		picture_list.append(pic_div);
	}
	
	function remove_picture(index, picture) {
		$('#div_picture'+index).remove();
		$.post('/admin/?act=remove_picture', {pic_name:picture,location_code:'<?php echo $location_code ?>'});
	}
</script>